package com.dyava.commons.validate;

import org.apache.commons.lang3.time.DateFormatUtils;

import java.util.Date;

public class ValidateDate extends Validate<Date,ValidateDate> {

	public ValidateDate(Date value, String name) {
		this.value = value;
		this.name = name;
	}

	public ValidateDate gt(Date value){
		if (checkNull()) return this;
		if(this.value.compareTo(value)>0){
			return this;
		}
		throw new ValidateFastException(name+"必须大于"+ DateFormatUtils.format(value,"yyyy-MM-dd HH:mm:ss"));
	}

	public ValidateDate lt(Date value){
		if (checkNull()) return this;
		if(this.value.compareTo(value)<0){
			return this;
		}
		throw new ValidateFastException(name+"必须小于"+ DateFormatUtils.format(value,"yyyy-MM-dd HH:mm:ss"));
	}

	public ValidateDate ge(Date value){
		if (checkNull()) return this;
		if(this.value.compareTo(value)>=0){
			return this;
		}
		throw new ValidateFastException(name+"必须大于等于"+ DateFormatUtils.format(value,"yyyy-MM-dd HH:mm:ss"));
	}

	public ValidateDate le(Date value){
		if (checkNull()) return this;
		if(this.value.compareTo(value)<=0){
			return this;
		}
		throw new ValidateFastException(name+"必须小于等于"+ DateFormatUtils.format(value,"yyyy-MM-dd HH:mm:ss"));
	}





}
